import Vue from "vue"
import App from "./App.vue"
import Vuex from "vuex"
import router from "./router"
import store from "./store"

Vue.config.productionTip = false

Vue.use(Vuex)

Vue.prototype.$store = store

router.beforeEach((to, from, next) => {
    console.log(store.state, "路由加载之前检查store.state")
    console.info('当前路径是:',to.path)
    if (store.state.userInfo || to.path === "/login") {
        console.info('用户信息:',store.state.userInfo)
        next()
    } else {
        console.info('用户信息不存在')
        next({
            path: "/login"
        })
    }
})

new Vue({
    store,
    router,
    render: h => h(App)
}).$mount("#app")
